const { fnm, fnm_s } = require('../test-utils');
/**
 *
 * @param {import('webpack').Compilation} compilation
 */
function recordModulesAndChunks(compilation) {
  const name = '个人测试 TestCompilationPlugin-RecordModulesAndChunks';

  compilation.hooks.reviveModules.tap(name, (modules, records) => {
    console.log('------------- reviveModules');
  });
  compilation.hooks.beforeModuleIds.tap(name, (modules) => {
    console.log('------------- beforeModuleIds');
  });
  compilation.hooks.moduleIds.tap(name, (modules) => {
    console.log('------------- moduleIds');
  });
  compilation.hooks.optimizeModuleIds.tap(name, (modules) => {
    console.log('------------- optimizeModuleIds');
  });
  compilation.hooks.afterOptimizeModuleIds.tap(name, (modules) => {
    console.log('------------- afterOptimizeModuleIds');
  });
  compilation.hooks.reviveChunks.tap(name, (chunks, records) => {
    console.log('------------- reviveChunks');
  });
  compilation.hooks.beforeChunkIds.tap(name, (chunks) => {
    console.log('------------- beforeChunkIds');
  });
  compilation.hooks.chunkIds.tap(name, (chunks) => {
    console.log('------------- chunkIds');
  });
  compilation.hooks.optimizeChunkIds.tap(name, (chunks) => {
    console.log('------------- optimizeChunkIds');
  });
  compilation.hooks.afterOptimizeChunkIds.tap(name, (chunks) => {
    console.log('------------- afterOptimizeChunkIds');
  });
  compilation.hooks.recordModules.tap(name, (modules, records) => {
    console.log('------------- recordModules');
  });
  compilation.hooks.recordChunks.tap(name, (chunks, records) => {
    console.log('------------- recordChunks');
  });
}

/**
 *
 * @param {import('webpack').Compilation} compilation
 */
function recordHash(compilation) {
  const name = '个人测试 TestCompilationPlugin-RecordHash';
  compilation.hooks.beforeModuleHash.tap(name, () => {
    console.log('------------- beforeModuleHash');
  });
  compilation.hooks.afterModuleHash.tap(name, () => {
    console.log('------------- afterModuleHash');
  });
  compilation.hooks.beforeHash.tap(name, () => {
    console.log('------------- beforeHash');
  });
  compilation.hooks.chunkHash.tap(name, (chunk, chunkHash, chunkHashContext) => {
    console.log('------------- chunkHash');
  });
  compilation.hooks.afterHash.tap(name, () => {
    console.log('------------- afterHash');
  });
  compilation.hooks.recordHash.tap(name, (records) => {
    console.log('------------- recordHash');
  });
}

/**
 *
 * @param {import('webpack').Compilation} compilation
 */
module.exports = function (compilation) {
  const name = '个人测试 TestCompilationPlugin';
  compilation.hooks.shouldRecord.tap(name, () => {
    console.log('------------- shouldRecord'); // 这个是bail钩子，不能返回false
    // return true;
  });

  recordModulesAndChunks(compilation);
  recordHash(compilation);
  compilation.hooks.record.tap(name, (compilation, records) => {
    console.log('------------- record');
  });
};
